
function changeFace(){
    var reader = new FileReader();//定义文件读取流对象
    reader.readAsDataURL(document.getElementById("fileTxt").files[0]);
    reader.onload = function (ev) {
        document.getElementById("faceImg").src = ev.target.result;
    }
}

//添加
async function add(){
    var formObj = new FormData();
    formObj.append("uploadImg",$("fileTxt").files[0]);

    let config = {
        headers: {'Content-Type': 'multipart/form-data' }
    }
    var uploadFileName;
    //向服务器上传文件，得到上传文件名
    await  axios.post("/upload",formObj,config).then(resp =>{
        uploadFileName = resp.data;
    });

    // alert(uploadFileName);
    axios.get("/em/add",{
        params:{
            name: $("nameTxt").value,
            phone:$("phoneTxt").value,
            money:$("moneyTxt").value,
            imgPath: uploadFileName
        }
    }).then(resp =>{
        // alert(JSON.stringify(resp.data));
        var info = resp.data;
        if(info == "ok"){
            location.href = "/main.html";
        }
        else{
            //在span标签中显示错误信息
            info.forEach(n=>{
               $(n.field+"Span").innerHTML = n.defaultMessage;
            });
        }
    })
}